﻿package newXgame.hall
{
	import flash.display.StageAlign;
	import flash.events.Event;
	
	import newXgame.hall.globals.Globals;
	import newXgame.hall.object.GameListObject;
	import newXgame.hall.object.MessageListObject;
	import newXgame.hall.object.TableListObject;
	import newXgame.hall.object.UserLoginObject;
	import newXgame.hall.object.background.HallBackground;
	
	import org.dstart.draw.csuper.CSprite;

	public class GameHallMain extends CSprite
	{
		private var mcHallBackground:HallBackground;	//	游戏大厅背景
		private var mcGameList:GameListObject;			//	游戏列表
		private var mcTableList:TableListObject;		//	桌子列表
		private var mcMsgList:MessageListObject;		//	信息列表
		private var mcLogin:UserLoginObject;			//	用户登陆框
		
		private var g:Globals; 
		
		public function GameHallMain()
		{
			g = Globals.getObject();
			
			mcHallBackground = new HallBackground();
			mcGameList = new GameListObject();
			mcTableList = new TableListObject();
			mcMsgList = new MessageListObject();
			mcLogin = new UserLoginObject();
			
			mcGameList.ChangeSize(g.listBaseWidth, g.listBaseWidth);
			mcTableList.ChangeSize(300, 300);
			
			// mcLogin.visible = false;
			
			_root.addChild(mcHallBackground);		
			_root.addChild(mcGameList);
			_root.addChild(mcTableList);		
			_root.addChild(mcMsgList);	
			
			this.addChild(mcLogin);
			
			this.addEventListener(Event.ADDED_TO_STAGE, onShowInStage);			
		}
		
		private function onShowInStage(e:Event):void
		{
			onReSizeEvent(null);
			
			this.stage.align = StageAlign.TOP_LEFT;
			this.stage.addEventListener(Event.RESIZE, onReSizeEvent);
		}
		
		private function onReSizeEvent(e:Event):void
		{
			var xBase:Number = g.xSpace;
			var yBase:Number = g.ySpace;
			var wMax:Number = this.stage.stageWidth - xBase * 2;
			var hMax:Number = this.stage.stageHeight - yBase * 2;
			
			wMax = (wMax < g.minWidth + xBase * 2) ? g.minWidth + xBase * 2 : wMax;
			hMax = (hMax < g.minHeight + yBase * 2) ? g.minHeight + yBase * 2 : hMax;
			
			xBase += 4;
			yBase += 4;			
			
			this.mcHallBackground.ChangeSize(wMax, hMax);
			this.mcGameList.ChangeSize(this.mcGameList.objWidth, hMax - g.listBaseY - g.listBaseEnd);
			this.mcTableList.ChangeSize(wMax - this.mcGameList.objWidth - g.listBaseX - g.tableBaseRight - g.resizeObjWidth, 
										hMax - g.listBaseY - g.listBaseEnd - g.talkBaseHeight - g.resizeObjWidth);
			this.mcMsgList.ChangeSize(wMax - this.mcGameList.objWidth - g.listBaseX - g.tableBaseRight - g.resizeObjWidth, 
										g.talkBaseHeight);

			this.mcHallBackground.SetPlace(xBase, yBase);
			this.mcGameList.SetPlace(xBase + g.listBaseX, yBase + g.listBaseY);
			this.mcTableList.SetPlace(xBase + g.listBaseX + this.mcGameList.objWidth + g.resizeObjWidth, yBase + g.listBaseY);
			this.mcMsgList.SetPlace(this.mcTableList.x, 
									yBase + hMax - g.talkBaseHeight - g.listBaseEnd);
			
			this.mcLogin.visible = false;
			this.mcLogin.SetPlace((wMax - this.mcLogin.objWidth)/2, (hMax - this.mcLogin.objHeight)/2);
		}
	}
}